People using EC2 backed ECS cluster can understand the pain which goes in to maintaining and patching the base machines running our ECS containers.We usually pick two paths
- Use ECS optimized AMI maintained by AWS.
- Use custom AMI with patching on our convenience.
Let us the see pros and cons with both the methods.
ECS optimized AMI images
Pros:
- AWS updates base AMI periodically for us with latest security patches.
- AWS regularly pushes AMI with updated ECS agent,Docker versions and dependencies.
Cons:
- Older AMI’s disappears and will not available.
- If you have hardcoded your Launch template/Configuration,cluster goes down when AMI is no longer available.
- Compatibility issues may occur with the newer versions,especially in case of Windows Containers.
Solution to prevent hard coded AMI names using Terraform.
We can create Terraform resource as below to always fetch latest ECS optimized image provided by Amazon and then use it in our launch configuration or template
Self managed ECS AMI
Pros:
- We can retain total control of ownership and maintenance of the AMI image.
- We can enforce additional security and custom patching cycles.
Cons:
- Obviously the burden to maintain the images falls on us.
- AMI storage cost might increase depending on our versioning strategy.
- Resources are required to pick latest ECS agent, docker version etc., test and update.
Finally
Whichever path we pick , the burden to change and upgrade our ECS cluster launch configuration falls on us.Although using and IAC like Terraform would make it easy to quickly update.
Do let me know if there are bette ways to maintain the AMI and EC2 backed ECS clusters.